﻿function edit(bh)  //转到编辑页面
{
    var selectedRow = $('#tt').datagrid('getSelected');  //获取选中行
    //单选题
    $('#tbsingle').datagrid({

        idField: 'ID',
        url: 'Handler/UserAnswerHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>&userid=' + selectedRow.UserID + '&paperid=' + selectedRow.PaperID + '&scoreid=' + selectedRow.ID + '&answertype=单选题', //?startIndex=0&endIndex=20  /''+ index +'/'
        singleSelect: true,
        columns: [[
                   { field: 'ID', title: '序号', width: 80 },
                  { field: 'UserID', title: '工号', width: 100 },
                  { field: 'PaperID', title: '试卷编号', width: 80 },
                  { field: 'SingleProblemMark', title: '单选题', width: 80 },
                  { field: 'MultiProblemMark', title: '多选题', width: 80 },
                  { field: 'JudgeProblemMark', title: '判断题', width: 80 },
                  { field: 'FillBlankProblemMark', title: '填空题', width: 80 },
                  { field: 'QuestionProblemMark', title: '问答题', width: 80 },

                  { field: 'opt', title: '操作', width: 100, align: 'center',
                      formatter: function (value, rec, index) {
                          var e = '<a href="#" mce_href="#" onclick="edit(' + rec.ID + ')">批卷</a> ';
                          var d = '<a href="#" mce_href="#" onclick="del(' + index + ')">删除</a> ';
                          return e;
                      }
                  }
                ]], toolbar: [{
                    text: '增加', iconCls: 'icon-add', handler: function () {
                        //add();
                    }
                },
                { text: '查找', iconCls: 'icon-search' }
                ],
        pagination: true, rownumbers: true
    });
    //多选题
    $('#tbmulti').datagrid({

        idField: 'ID',
        url: 'Handler/UserAnswerHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>&userid=' + selectedRow.UserID + '&paperid=' + selectedRow.PaperID + '&scoreid=' + selectedRow.ID + '&answertype=多选题', //?startIndex=0&endIndex=20  /''+ index +'/'
        singleSelect: true,
        columns: [[
                   { field: 'ID', title: '序号', width: 80 },
                  { field: 'UserID', title: '工号', width: 100 },
                  { field: 'PaperID', title: '试卷编号', width: 80 },
                  { field: 'SingleProblemMark', title: '单选题', width: 80 },
                  { field: 'MultiProblemMark', title: '多选题', width: 80 },
                  { field: 'JudgeProblemMark', title: '判断题', width: 80 },
                  { field: 'FillBlankProblemMark', title: '填空题', width: 80 },
                  { field: 'QuestionProblemMark', title: '问答题', width: 80 },

                  { field: 'opt', title: '操作', width: 100, align: 'center',
                      formatter: function (value, rec, index) {
                          var e = '<a href="#" mce_href="#" onclick="edit(' + rec.ID + ')">批卷</a> ';
                          var d = '<a href="#" mce_href="#" onclick="del(' + index + ')">删除</a> ';
                          return e;
                      }
                  }
                ]], toolbar: [{
                    text: '增加', iconCls: 'icon-add', handler: function () {
                        //add();
                    }
                },
                { text: '查找', iconCls: 'icon-search' }
                ],
        pagination: true, rownumbers: true
    });
    //判断题
    $('#tbjudge').datagrid({

        idField: 'ID',
        url: 'Handler/UserAnswerHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>&userid=' + selectedRow.UserID + '&paperid=' + selectedRow.PaperID + '&scoreid=' + selectedRow.ID + '&answertype=判断题', //?startIndex=0&endIndex=20  /''+ index +'/'
        singleSelect: true,
        columns: [[
                   { field: 'ID', title: '序号', width: 80 },
                  { field: 'UserID', title: '工号', width: 100 },
                  { field: 'PaperID', title: '试卷编号', width: 80 },
                  { field: 'SingleProblemMark', title: '单选题', width: 80 },
                  { field: 'MultiProblemMark', title: '多选题', width: 80 },
                  { field: 'JudgeProblemMark', title: '判断题', width: 80 },
                  { field: 'FillBlankProblemMark', title: '填空题', width: 80 },
                  { field: 'QuestionProblemMark', title: '问答题', width: 80 },

                  { field: 'opt', title: '操作', width: 100, align: 'center',
                      formatter: function (value, rec, index) {
                          var e = '<a href="#" mce_href="#" onclick="edit(' + rec.ID + ')">批卷</a> ';
                          var d = '<a href="#" mce_href="#" onclick="del(' + index + ')">删除</a> ';
                          return e;
                      }
                  }
                ]], toolbar: [{
                    text: '增加', iconCls: 'icon-add', handler: function () {
                        //add();
                    }
                },
                { text: '查找', iconCls: 'icon-search' }
                ],
        pagination: true, rownumbers: true
    });
    //填空题
    $('#tbfillblank').datagrid({

        idField: 'ID',
        url: 'Handler/UserAnswerHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>&userid=' + selectedRow.UserID + '&paperid=' + selectedRow.PaperID + '&scoreid=' + selectedRow.ID + '&answertype=填空题', //?startIndex=0&endIndex=20  /''+ index +'/'
        singleSelect: true,
        columns: [[
                   { field: 'ID', title: '序号', width: 80 },
                  { field: 'UserID', title: '工号', width: 100 },
                  { field: 'PaperID', title: '试卷编号', width: 80 },
                  { field: 'SingleProblemMark', title: '单选题', width: 80 },
                  { field: 'MultiProblemMark', title: '多选题', width: 80 },
                  { field: 'JudgeProblemMark', title: '判断题', width: 80 },
                  { field: 'FillBlankProblemMark', title: '填空题', width: 80 },
                  { field: 'QuestionProblemMark', title: '问答题', width: 80 },

                  { field: 'opt', title: '操作', width: 100, align: 'center',
                      formatter: function (value, rec, index) {
                          var e = '<a href="#" mce_href="#" onclick="edit(' + rec.ID + ')">批卷</a> ';
                          var d = '<a href="#" mce_href="#" onclick="del(' + index + ')">删除</a> ';
                          return e;
                      }
                  }
                ]], toolbar: [{
                    text: '增加', iconCls: 'icon-add', handler: function () {
                        //add();
                    }
                },
                { text: '查找', iconCls: 'icon-search' }
                ],
        pagination: true, rownumbers: true
    });
    //问答题
    $('#tbquestion').datagrid({

        idField: 'ID',
        url: 'Handler/UserAnswerHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>&userid=' + selectedRow.UserID + '&paperid=' + selectedRow.PaperID + '&scoreid=' + selectedRow.ID + '&answertype=问答题', //?startIndex=0&endIndex=20  /''+ index +'/'
        singleSelect: true,
        columns: [[
                   { field: 'ID', title: '序号', width: 80 },
                  { field: 'UserID', title: '工号', width: 100 },
                  { field: 'PaperID', title: '试卷编号', width: 80 },
                  { field: 'SingleProblemMark', title: '单选题', width: 80 },
                  { field: 'MultiProblemMark', title: '多选题', width: 80 },
                  { field: 'JudgeProblemMark', title: '判断题', width: 80 },
                  { field: 'FillBlankProblemMark', title: '填空题', width: 80 },
                  { field: 'QuestionProblemMark', title: '问答题', width: 80 },

                  { field: 'opt', title: '操作', width: 100, align: 'center',
                      formatter: function (value, rec, index) {
                          var e = '<a href="#" mce_href="#" onclick="edit(' + rec.ID + ')">批卷</a> ';
                          var d = '<a href="#" mce_href="#" onclick="del(' + index + ')">删除</a> ';
                          return e;
                      }
                  }
                ]], toolbar: [{
                    text: '增加', iconCls: 'icon-add', handler: function () {
                        //add();
                    }
                },
                { text: '查找', iconCls: 'icon-search' }
                ],
        pagination: true, rownumbers: true
    });


    //window.location.href = 'StuEdit.aspx?id=' + bh;

}
function view(bh)  //转到查看页面
{
    window.location.href = 'StuView.aspx?id=' + bh + '&page=stu';

}

function add() {
    $("#hdType").val("addsave");
    $("#hdID").val("");
    $("#txtTitle").val("");
    $("#txtAnswer").val("");
    $("#selectDep").attr("value", '<%=Umodel.DepID %>');
    $('#dd').dialog('open').dialog('setTitle', '用户成绩');
}

function save() {

    $('#ff').form('submit', {
        url: 'Handler/ScoreHandler.ashx?d=' + new Date().getMilliseconds() + '&type=' + $("#hdType").val(),
        onSubmit: function () {
            return $(this).form('validate');
        },
        success: function (data) {
            if (data > 0) {
                $.messager.alert('操作结果', "执行成功，编号为：" + data, 'info');
                $('#dd').dialog('close')
            }
        }
    });
    $('#tt').datagrid('reload');

    // $("#ff").submit();
}

function del(index) {  //删除操作
    $.messager.confirm('确认', '确认删除?', function (row) {
        if (row) {
            var selectedRow = $('#tt').datagrid('getSelected');  //获取选中行
            $.ajax({
                url: 'Handler/ScoreHandler.ashx?type=del&id=' + selectedRow.ID,
                //加了个type，作用是以后不管什么删除，都可以转到这个ashx中处理
                success: function () { $.messager.alert('操作结果', "删除成功，编号为：" + selectedRow.ID, 'info'); }
            });
            $('#tt').datagrid('deleteRow', index);
        }
    })
}